package com.rd.student.dashuju.wangbo.day08_01;

import java.util.Arrays;

public class SelectionSort {

    public static void main(String[] args) {
        int[] arr ={60,33,55,88,70,90,99};
        sortDownTest(arr);
        sortTest(arr);
    }

    public static void sortDownTest(int[] arr){
        for (int i = 0; i < arr.length - 1; i++) {
            int max = i;
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[j] > arr[max]){
                    max = j;
                }
                if (max != i) {
                    int temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }
        }
        System.out.println("从大到小排序为：");
        System.out.println(Arrays.toString(arr));
    }

    public static void sortTest(int[] arr){
        for (int i = 0; i < arr.length - 1; i++) {
            int min = i;
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[j] < arr[min]){
                    min = j;
                }
                if (min != i) {
                    int temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }
        }
        System.out.println("从小到大排序为：");
        System.out.println(Arrays.toString(arr));
    }
}
